﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;

namespace IFRS.DataAccess.DAL
{
    public class COLLATERALMANUAL
    {
        public DataTable SEARCH_ALL(CollateralManual CollateralManual, Paging paging, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@TransactionDate", CollateralManual.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@SOURCEDATAID", CollateralManual.SourceDataID.AsDBValue()));
                lstParams.Add(new SqlParameter("@ACCOUNTNO", CollateralManual.AccountNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@COLLATERALNO", CollateralManual.CollateralNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@COLLATERALTYPENAMETH", CollateralManual.CollateralTypeNameTH.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_COLLATERALMANUAL_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int iCOLLATERALMANUALID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@COLLATERALMANUALID", iCOLLATERALMANUALID));
                dt = Utility.StoredProcDataTable("SPR_COLLATERALMANUAL_SEARCHBYID", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(CollateralManual CollateralManual)
        {
            int iNum;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@CollateralManualID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;

                lstParams.Add(new SqlParameter("@TransactionDate", CollateralManual.TransactionDate));
                lstParams.Add(new SqlParameter("@SourceDataID", CollateralManual.SourceDataID));
                lstParams.Add(new SqlParameter("@AccountNo", CollateralManual.AccountNo));
                lstParams.Add(new SqlParameter("@CollateralNo", CollateralManual.CollateralNo));
                lstParams.Add(new SqlParameter("@CollateralTypeID", CollateralManual.CollateralTypeID));
                lstParams.Add(new SqlParameter("@CollateralValue", CollateralManual.CollateralValue));
                lstParams.Add(new SqlParameter("@IsConfirmed", CollateralManual.IsConfirmed));
                lstParams.Add(new SqlParameter("@CreatedDate", CollateralManual.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", CollateralManual.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", CollateralManual.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", CollateralManual.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", CollateralManual.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", CollateralManual.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", CollateralManual.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", CollateralManual.UpdatedBranch));

                utility.ExecuteStoredProc("SPR_CollateralManual_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(CollateralManual CollateralManual)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@CollateralManualID", CollateralManual.CollateralManualID));
                lstParams.Add(new SqlParameter("@TransactionDate", CollateralManual.TransactionDate));
                lstParams.Add(new SqlParameter("@SourceDataID", CollateralManual.SourceDataID));
                lstParams.Add(new SqlParameter("@AccountNo", CollateralManual.AccountNo));
                lstParams.Add(new SqlParameter("@CollateralNo", CollateralManual.CollateralNo));
                lstParams.Add(new SqlParameter("@CollateralTypeID", CollateralManual.CollateralTypeID));
                lstParams.Add(new SqlParameter("@CollateralValue", CollateralManual.CollateralValue));
                lstParams.Add(new SqlParameter("@IsConfirmed", CollateralManual.IsConfirmed));
                lstParams.Add(new SqlParameter("@UpdatedDate", CollateralManual.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", CollateralManual.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", CollateralManual.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", CollateralManual.UpdatedBranch));

                iNum = (int)Utility.ExecuteStoredProc("SPR_CollateralManual_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(int iCOLLATERALMANUALID)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@COLLATERALMANUALID", iCOLLATERALMANUALID));
                iNum = (int)Utility.ExecuteStoredProc("SPR_COLLATERALMANUAL_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
    }
}
